<button type="button" data-controller="dropdown" data-target="actions-component-<%= component.id %>" aria-label="<%= t("decidim.admin.actions.actions_label", resource: component.manifest.name) %>">
  <%= icon "more-fill", class: "text-secondary" %>
</button>

<div class="inline-block relative">
  <ul id="actions-component-<%= component.id %>" class="dropdown dropdown__action" aria-hidden="true">
    <% if view == :deleted %>
      <% if allowed_to? :restore, :component, trashable_deleted_resource: component %>
        <li class="dropdown__item">
          <%= link_to url_for(action: :restore, id: component, controller: "components"), method: :patch, class: "dropdown__button" do %>
            <%= icon "refresh-line" %>
            <%= t("decidim.admin.actions.restore") %>
          <% end %>
        </li>
      <% end %>
    <% else %>
      <% if component.manifest.admin_engine %>
        <li class="dropdown__item">
          <%= link_to manage_component_path(component), class: "dropdown__button" do %>
            <%= icon "pencil-line" %>
            <%= t("actions.edit", scope: "decidim.admin") %>
          <% end %>
        </li>
      <% end %>

      <% if allowed_to? :update, :component, component: component %>
        <li class="dropdown__item">
          <%= link_to url_for(action: :edit, id: component, controller: "components"), class: "dropdown__button" do %>
            <%= icon "settings-4-line" %>
            <%= t("actions.configure", scope: "decidim.admin") %>
          <% end %>
        </li>

        <hr>
      <% end %>

      <% if allowed_to?(:update, :component, component: component) %>
        <% if component.published? %>
          <% if component.visible? %>
            <li class="dropdown__item">
              <%= link_to url_for(action: :hide, id: component, controller: "components"), method: :put, class: "dropdown__button" do %>
                <%= icon "eye-close" %>
                <%= t("actions.menu_hidden", scope: "decidim.admin") %>
              <% end %>
            </li>
          <% else %>
            <li class="dropdown__item">
              <%= link_to url_for(action: :unpublish, id: component, controller: "components"), method: :put, class: "dropdown__button" do %>
                <%= icon "close-circle-line" %>
                <%= t("actions.unpublish", scope: "decidim.admin") %>
              <% end %>
            </li>
          <% end %>
        <% else %>
          <li class="dropdown__item">
            <%= link_to url_for(action: :publish, id: component, controller: "components"), method: :put, class: "dropdown__button" do %>
              <%= icon "check-line" %>
              <%= t("actions.publish", scope: "decidim.admin") %>
            <% end %>
          </li>
        <% end %>

        <hr>
      <% end %>

      <li class="dropdown__item">
        <%= link_to main_component_path(component), class: "dropdown__button", target: "_blank", data: { "external-link": false } do %>
          <%= icon "eye-line" %>
          <%= t("actions.preview", scope: "decidim.admin") %>
        <% end %>
      </li>

      <% if component.manifest.admin_engine && allowed_to?(:share, :component, component: component) %>
        <li class="dropdown__item">
          <%= link_to component_share_tokens_path(component_id: component), class: "dropdown__button" do %>
            <%= icon "share-line" %>
            <%= t("actions.share_tokens", scope: "decidim.admin") %>
          <% end %>
        </li>

        <hr>
      <% end %>

      <% if allowed_to? :update, :component, component: component %>
        <% if component.manifest.actions.any? %>
          <li class="dropdown__item">
            <%= link_to url_for(action: :edit, component_id: component, controller: "component_permissions"), class: "dropdown__button" do %>
              <%= icon "key-2-line" %>
              <%= t("actions.permissions", scope: "decidim.admin") %>
            <% end %>
          </li>
        <% end %>
      <% end %>

      <% if allowed_to?(:soft_delete, :component, trashable_deleted_resource: component) %>
        <% resources_count = component.primary_stat || 0 %>
        <% if component.published? %>
          <hr>
          <li class="dropdown__item">
            <div class="dropdown__button-disabled">
              <%= with_tooltip t("tooltips.deleted_component_info", scope: "decidim.admin") do %>
                <%= icon "delete-bin-line", class: "text-gray" %>
                <span>
                  <%= t("actions.soft_delete", scope: "decidim.admin") %>
                </span>
              <% end %>
            </div>
          </li>
        <% else %>
          <hr>
          <li class="dropdown__item">
            <%= link_to url_for(action: :soft_delete, id: component, controller: "components"), method: :patch, class: "dropdown__button dropdown__button--danger", data: { confirm: t("actions.confirm_delete_component", scope: "decidim.admin", resources_count:) } do %>
              <%= icon "delete-bin-line" %>
              <%= t("actions.soft_delete", scope: "decidim.admin", resources_count:) %>
            <% end %>
          </li>
        <% end %>
      <% end %>
    <% end %>
  </ul>
</div>
